package cn.tedu.controller;

import cn.tedu.pojo.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UserController {

    /*
    获取所有的用户信息
    http://localhost:8080/getUsers
     */
    @GetMapping("/getUsers")
    public List<User> getUsers(String name){
        System.out.println("前端传过来的"+name);
        User user1 = new User();
        user1.setName("小明");
        user1.setId(1001L);
        user1.setPassword("123");
        user1.setPhone("13056789900");

        User user2 = new User();
        user2.setName("小亮");
        user2.setId(1002L);
        user2.setPassword("123");
        user2.setPhone("13056789911");
        ArrayList<User> users = new ArrayList<>();
        users.add(user1);
        users.add(user2);
        return users;

    }

    /**
     * 用户登录接口
     * @param username
     * @param password
     * @return
     */
    @PostMapping("/login")
    public String login(String username,String password){
        System.out.println(username+"=="+password);
        if ("小明".equals(username) && "123".equals(password)){
            return "登录成功";
        }
        return "登录失败";
    }

}
